package com.frank.auth.domain.service.impl;

import com.frank.auth.domain.bo.AuthRolePermissionBo;
import com.frank.auth.domain.service.RolePermissionDomainService;
import com.frank.auth.infra.basic.entity.AuthRolePermission;
import com.frank.auth.infra.basic.service.AuthRolePermissionService;
import org.springframework.stereotype.Service;

import java.util.LinkedList;
import java.util.List;

/**
 * @author Frank Zou
 * @version v0.0.1
 * @date 2024/2/14
 * @description
 */
@Service
public class RolePermissionDomainServiceImpl implements RolePermissionDomainService {

    private final AuthRolePermissionService authRolePermissionService;

    public RolePermissionDomainServiceImpl(AuthRolePermissionService authRolePermissionService) {
        this.authRolePermissionService = authRolePermissionService;
    }

    @Override
    public Boolean addRolePermission(AuthRolePermissionBo authRolePermissionBo) {
        List<AuthRolePermission> authRolePermissions = new LinkedList<>();
        Long roleId = authRolePermissionBo.getRoleId();
        authRolePermissionBo.getPermissionIdList().forEach(permissionId -> {
            AuthRolePermission authRolePermission = new AuthRolePermission();
            authRolePermission.setRoleId(roleId);
            authRolePermission.setPermissionId(permissionId);
            authRolePermissions.add(authRolePermission);
        });
        return authRolePermissionService.saveBatch(authRolePermissions);
    }
}
